import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException ;

public class QuestionToDatabase{

	private DataBaseManagement dataBaseManagement;

	public QuestionToDatabase(){
		dataBaseManagement = new DataBaseManagement(); //create a DataBaseManagement for using the methods provided
	}

	public DataBaseManagement getDataBaseManagement(){
		return dataBaseManagement;
	}
	public void setDataBaseManagement(DataBaseManagement dataBaseManagement){
		this.dataBaseManagement = dataBaseManagement;
	}

	public void readFile(String fileName){
		try{
			
			FileReader fr = new FileReader(fileName);
			BufferedReader br = new BufferedReader(fr);//for reading file
			
			String line = ""; //holds each line read from the data file
			String[] attributes; //used to hold the field going to be store into the database
			
			//read the data file line by line
			while((line = br.readLine())!=null){
				//read all the lines in the file
				
				attributes = line.split(";"); //split the line into strings
				dataBaseManagement.writeQuestionToDataBase(attributes); //write the data to the database according to the specified order of the fields
			}
			
			br.close(); //close the file
		}catch(IOException e){
			System.err.println(e.getMessage());
		}
	}

	public static void main(String para[]){
		QuestionToDatabase app = new QuestionToDatabase();
		app.getDataBaseManagement().create();
		app.readFile("qdb.txt");
	}
}